<template>
  <div :id="self.name"
  style="position: relative;
          width: 100%;
          height: 90vh;
          margin: 0;
          padding: 0;"
  >
    
  </div>
</template>

<script>
import { ref, unref, watch } from 'vue'
import { init } from '/src/utils/base'
import { init as initBase } from './base'

import { post } from "/src/api/index";

export default {
    emits: ['baseMounted'],
    
    setup() {
        let self = {}

        //必须先设置，否则initBase时无法取到这个值
        self.button_add_visible = false
        self.button_item_edit_visible = false

        initBase(self)
        
        init(self)

        const baseMounted = (v) => {
          self.onMounted(v);
        }
        

        let columns = [
          {
            name:'table_name',
            sortable: true,
          },
          {
            name:'update_time',
            sortable: true,
          },
          {
            name: 'content',
            "type": "tpl",
            sortable: true,
            edit: {
              type: 'textarea',
              onEvent: self.amis.onEditChange,
            },
            copyable: true,
            "tpl": "${content|truncate:60}",
            "popOverEnableOn": "${ content && content.length > 60 }",
            "popOver": {
              trigger: 'hover',
              "position": "left-top",
              "showIcon": true,
              "title": {
                type: "operation",
                buttons: [   
                  {
                    type: "button",
                    label: "复制",
                    "actionType": "copy",
                    "content": "${content}",
                  },
                ],
              },
              "body": {
                "type": "tpl",
                "tpl": "${content}"
              }
            }
          },
        ]

        self.amis.init({columns,
          insert_edit_actions:[
          ],
          insert_edit_bulk_actions: [
          ],
          append_header_actions: [
          {
              type: "button",
              level: "warning",
              align: "right",
              label: "清空",
              confirmText: "确定要清空历史",
              loadingOn: "${button_batch_clear_history_loading}",
              onEvent: {
                click: {
                  actions: [
                    {
                      actionType: "custom",
                      script: (a,b,c,d,e,f) => {
                        let ret = self.amis.onAction(a,b,c,d,e,f, )
                        post('sdp_history', 'clear', {})
                        .then(() => {
                          ret.crudComponent.handleQuery();
                          b({actionType: 'closeDialog'})
                        })
                      },
                    },
                  ],
                },
              }
            },
          ],
        })

        let schema = {
          ...self.amis.page_schema,
          body: [    
            {
              type: "crud",
              ...self.amis.commonSchema.crud,
              bulkActions: [
                {...self.amis.commonSchema.bulkActions.delete},
              ],
              filter: {
                title: '',
                persistData:unref(self.name)+'_filter',
                body: [
                  {...self.amis.commonSchema.filter.page_title},
                  {
                    type: "input-text",
                    name: "table_name_like",
                    "clearable": true,
                    "placeholder": "请输入表",
                    static: false,
                    width: 200,
                    size:'sm',
                  },
                  {
                    type: "input-text",
                    name: "content_like",
                    "clearable": true,
                    "placeholder": "请输入内容",
                    static: false,
                    width: 200,
                    size:'sm',
                  },
                  {...self.amis.commonSchema.filter.search},
                ],
              },
            },
          ],
        }

        self.initAmis('#'+unref(self.name), schema)
        return {self:ref(self), baseMounted};
    },
};
</script>

